﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using BySoft.Server.Common.WebCommon;
using BySoft.Server.Common.Enum;
using BySoft.Server.Consts;
using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Schema;
using BySoft.Server.DataAccess;
namespace BySoft.Server.Business
{
    public partial class SysParametertype
    {


        #region 缓存刷新
        /// <summary>
        ///  参数类别的缓存刷新
        /// </summary>
        public static void RefreshWebCaching()
        {

            DataSet ds = SysParametertypeDA.GetAll();
            WebCaching.ALLPARAMETERTYPESCaching = ds;//缓存更新
        }
        #endregion

        #region IsIDExist
        /// <summary>
        ///  判断参数类别ID是否唯一（不包含删除的数据）,ID大小写不区分，当ID存在删除的数据中，out 参数为true;
        /// </summary>
        /// <param name="strID">类别ID</param>
        /// <returns>fale:已存在 true:不存在</returns>
        public static bool IsIDExist(string strID, out bool isExitsInDelete)
        {
            bool result = false;
            isExitsInDelete = false;
            SysParametertypeEntity entity = SysParametertypeDA.GetByID(strID);
            if (entity != null)
            {
                if (entity.Status == ((int)BaseEnum.CommonSatus.Delete).ToString())
                {
                    isExitsInDelete = true;
                }
                else
                {
                    result = true;
                }
            }
           

            return result;
        }
        #endregion

        #region IsNameExist
        /// <summary>
        ///  判断参数类别名称是否唯一
        /// </summary>
        /// <param name="strID"></param>
        /// <returns></returns>
        public static bool IsNameExist(string strName)
        {
            bool result = false;
            List<SysParametertypeEntity> list = SysParametertypeDA.GetByCondition("where " + SysParametertypeTable.C_PARAMETERTYPENAME + "='" + strName
                + "' and " + SysParametertypeTable.C_STATUS + "<>" + ((int)BaseEnum.CommonSatus.Delete).ToString());
            if (list != null && list.Count > 0)
            {
                result = true;
            }
            return result;
        }
        #endregion

        #region 数据插入
        public static bool Insert(SysParametertypeEntity entity)
        {
            if (entity == null)
                return false;

            if (OneSoft.DataAccess.DataAccessCommon.Insert(entity))
            {
                RefreshWebCaching();
                return true;
            }
            else
            {
                return false;
            }

        }
        #endregion

        #region 数据更新
        public static bool Update(SysParametertypeEntity entity)
        {
            if (SysParametertypeDA.Update(entity) > 0)
            {
                RefreshWebCaching();
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion

        #region  数据删除
        /// <summary>
        ///  根据ID删除数据,逻辑删除
        /// </summary>
        /// <param name="strID">参数类别ID</param>
        /// <returns>布尔值</returns>
        public static bool Delete(string strID)
        {
            Boolean result = false;
            if (SysParametertypeDA.UpdateSatus(strID, BaseEnum.CommonSatus.Delete) > 0)
            {
                RefreshWebCaching();
                result = true;
            }
            return result;

        }
        #endregion
    }
}